from socket import *

from threading import Thread

def recv_data():
    while True :
        # 接受服务器的数据
        recv_info = client_socket.recv(1024)
        recv_content = recv_info.decode()
        print(f"server say : {recv_content}")
        if recv_content == "over" :
            print("finished connection")
            break

def send_data():
    while True:
        msg = input(">")
        client_socket.send(msg.encode())
        if msg == "over" :
            print("finished connection")
            break

if __name__ == '__main__':
    client_socket = socket(AF_INET , SOCK_STREAM)
    client_socket.connect(("127.0.0.1" , 8899))

    t1 = Thread(target = recv_data)
    t2 = Thread(target = send_data)

    t1.start()
    t2.start()

    t1.join()
    t2.join()

    client_socket.close()